Repository navigation
fix(example-todo): give todo_task a days_overdue formula field so the overdue escalation notice renders its day count - #19205
Merged
huangyiirene merged 4 commits intoSep 19, 2026
Conversation
Claude-Session: https://claude.ai/code/session_01AhQASwqJr2Z7XfGWUdvnbF Co-authored-by: Claude <noreply@anthropic.com>
… escalation notice renders its day count
The overdue escalation notify body interpolates {currentTask.days_overdue}
and todo_task declared no such field, so the count rendered blank. Add it as
a formula: whole days past due_date, 0 when not overdue and 0 when due_date
is empty, via the registered daysBetween/today stdlib pair.
Claude-Session: https://claude.ai/code/session_01AhQASwqJr2Z7XfGWUdvnbF
Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AhQASwqJr2Z7XfGWUdvnbF Co-authored-by: Claude <noreply@anthropic.com>
This was referenced Sep 19, 2026
check:i18n-coverage counted the field's description as two new untranslated declared strings (106 -> 108): the translation key is `help`, and `en` is the source locale, so only zh-CN and ja-JP were missing it. Claude-Session: https://claude.ai/code/session_01AhQASwqJr2Z7XfGWUdvnbF Co-authored-by: Claude <noreply@anthropic.com>
huangyiirene
marked this pull request as ready for review
September 19, 2026 16:16
huangyiirene
deleted the
claude/issue-18584-days-overdue-formula-field
branch
September 19, 2026 16:42
akarma-synetal
pushed a commit
to akarma-synetal/framework
that referenced
this pull request
Sep 28, 2026
…rentTask` binds and the escalation notice is sent (objectstack-ai#19262) Fixes objectstack-ai#19206 `Clause-②: no` ## What was wrong Both `loop` nodes in `examples/app-todo/src/flows/task.flow.ts` declared `collection` + `iteratorVariable` and **no `config.body`**. That is the **legacy flat-graph** form: `packages/services/service-automation/src/builtin/loop-node.ts` opens with `if (raw.body == null)`, sets `$loopItems` / `$loopIndex` and returns **without binding `iteratorVariable`**. The per-item steps were wired as ordinary nodes *after* the container, so every `{currentTask.…}` token in them resolved to nothing. Measured on a real engine in this PR's control test (`CONTROL: the pre-fix body-less shape still dies at update_priority`): ``` update_record: refusing to run — 1 filter condition(s) resolved to nothing and were dropped from the query: `{currentTask.id}` (at id). ``` `notify_owner` sits one node **behind** that refusal, so **no escalation notice was sent at all** — and the control asserts that too (`emits` has length 0). `task_reminder` had the identical shape. ## The repair — established from the schema and the engine The authority is `LoopConfigSchema` / `FlowRegionSchema` in `packages/spec/src/automation/control-flow.zod.ts` (ADR-0031 representation **(B)**, nested sub-structure) plus the executor's structured branch: - `config.body` is a `FlowRegionSchema`: `{ nodes: min 1, edges: default [] }`, **single-entry / single-exit / acyclic** (`analyzeRegion`), rejected at `registerFlow()` via `validateControlFlow` when it is not. - The executor binds `iteratorVariable` in the **enclosing** scope per item and runs the region through `engine.runRegion`; the loop node's **ordinary out-edge is the after-loop continuation**, which is why `e3` now goes `loop → end`. Each body carries one `try_catch` (`flow-loop-body-uncontained`, the shape the lint rule's own hint prescribes, and the form `examples/app-showcase` already demonstrates), with the minimal handler — one bare `assignment` node. On `overdue_escalation` **one** `try_catch` wraps **both** per-item steps rather than one each: the notice announces the escalation the update performs, so a row whose update was refused must not be told its priority was raised. `maxIterations: 200` states, on the iterating side, the same bound the `get_record` step's `limit: 200` already imposes. ## What the notice actually renders — the reading this card unblocks With the loop body executing, the escalation notice is sent, and (composed with the `days_overdue` formula that landed in objectstack-ai#19205 / objectstack-ai#18584) it interpolates. Read off the captured `messaging.emit()` payload in a real run: ``` title: URGENT: task overdue — Alpha body: Due 2026-09-16, 4 day(s) overdue. ``` Three seeded rows render three distinct notices with their own owner, subject, due date and day count — no leaked binding, no blank hole. ## Tests `examples/app-todo/test/loop-body-iteration.test.ts` — drives the **real** flows on a real `AutomationEngine` over a real sqlite-wasm database holding the app's real `todo_task`. The only double is the `messaging` service, and it is a **capture**, not a simulation: capturing `emit()` is how the rendered title/body becomes readable at all. 1. ESCALATION — run succeeds, the seeded row's `priority` is `urgent` (so the body's first node matched the right row), exactly one notice, and its rendered body carries the real day count and no unresolved brace. 2. EVERY item is processed, each with its own values (a leaked binding would show as three identical notices). 3. CONTAINMENT — one row with an unresolvable recipient fails inside the body's `try_catch` and the sweep still reaches the rows after it. 4. REMINDER — the second loop in the file binds its iterator too. 5. CONTROL — the pre-fix body-less shape, rebuilt from the real flow, still dies at `update_priority` and notifies nobody. `test/overdue-escalation-days-overdue.test.ts` (the objectstack-ai#18584 pin) keeps pinning: its `node()` helper now walks the ADR-0031 region slots, because the nodes it inspects moved into the loop body. The question it asks is about those nodes' **config**, which nesting does not change. ## Evidence - `pnpm --filter @objectstack/example-todo exec vitest run` — **exit 0**, 7 files / 238 tests passed. - `pnpm --filter @objectstack/example-todo typecheck` — the package's own script is `tsc --noEmit` (read from its `package.json`, one leg) — **exit 0**. - `pnpm --filter '@objectstack/example-todo^...' build` — **exit 0**. - Gate families derived from the real change set with `node scripts/pm/dispatch-gates.mjs --repo objectstack-ai/objectstack --commands`: **37 derived, 37 run, 0 NOT-MEASURED, 0 UNRUN** (`--ran` reconciliation with exit codes recorded before any pipe). `check:dual-build-cjs-loads` first answered **exit 3 = PREREQUISITE NOT MET = not measured**; after the missing `dist/` was present it was re-run and answered **exit 0**. - `pnpm lint` (repo-wide `eslint . --no-inline-config`, the whole population, not a narrowed run) — **exit 0** at `c6ca194c2`. ## Changeset `skip-changeset`: `examples/app-todo/package.json` declares `"private": true` and the diff touches nothing else, so this publishes nothing from any released package. ## Scope `examples/app-todo/` only. No engine change was needed — and none was made: the container the schema already declares is what binds the iterator. `packages/spec/**` and `content/docs/releases/**` are untouched. ## Acceptance notes - `noted, not filed:` the two scheduled sweeps read date macros (`{tomorrow}`, `{3_days_ago}`) that `interpolateFilter` deliberately passes through verbatim for the data layer to resolve. Working as designed here; recorded only because the same brace syntax means something different one line away in the same config. Not a defect, not filed. --- _Generated by [Claude Code](https://claude.ai/code/session_01AhQASwqJr2Z7XfGWUdvnbF)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #18584
Clause-②: noThe
overdue_escalationnotification body interpolated{currentTask.days_overdue}whiletodo_taskdeclared no such field, so the day count rendered as a blank — silently, with no error. This adds the field as a formula, per the ruling on the card (issuecomment-5729189166, batch #158 item 2, letter 1, maintainer 「同意」 2026-09-18T11:14Z).The Zone-2 measurement, and the branch it selected
The ruling decided both branches in advance and made the route turn on one measurement: does the
get_record/loopprojection the flow iterates carry computed formula fields?Measured answer: YES → letter 1 executes. Driven, not inferred: a real kernel, real ObjectQL over a real in-process sqlite-wasm driver, the app's own
Taskobject, read the way the flow'sget_recordstep reads.The single condition that decides it is the projection.
ObjectQL.findrunsplanFormulaProjection(schema, ast.fields)(packages/objectql/src/engine.ts:1050), which evaluates every formula field on the schema whenfieldsis absent and only the named ones when it is present;applyFormulaPlanthen hydrates the rows beforefindreturns (engine.ts:10051).examples/app-todo/src/flows/task.flow.tsdeclares nofieldsonget_overdue_tasks, so the rows handed to the loop carry the computed value.What would have made the answer the other way: a
fieldslist on thatget_recordstep that did not namedays_overdue. That is why the first test in the new suite asserts the absence offieldsoff the app's own flow metadata rather than trusting it — adding one later is exactly the edit that would blank the count again, silently.Semantics, as ruled
Integer, whole days between
due_dateand now,0when not overdue and0whendue_dateis empty. No working-day calendar and no timezone option — "an example demonstrates the capability, not a scheduling product".Spelling deviates from the feasibility read in the ruling, semantics do not. The ruling's own text records
due_dateless-thannow()withint((now() - due_date) / duration('24h'))as the director's feasibility argument, explicitly untested. Verified against the actual formula surface in this tree and adopted the registered stdlib pair instead:daysBetween(a, b)is a registered stdlib function returningint(packages/formula/src/stdlib.ts:311), andtoday()is the platform's calendar-day function (calendarDayUtc, UTC by default). The pair IS the "UTC whole days" spelling, with no hand-rolled millisecond arithmetic — the same shapeexamples/app-crmalready uses fordays_to_close.returnType: 'number'carries the ruled "value type integer": the spec enum isnumber | text | boolean | date(packages/spec/src/data/field.zod.ts:1577), sonumberis what "integer" maps to on the real surface. Stated rather than silently dropped.Why a formula here does not contradict the paragraph above it in the same file
task.object.tscarries a long measured note explaining whyis_completed/is_overdueare NOT formulas: a formula field is virtual, so a filter naming one matches nothing. That reasoning is about filters, and it still holds.days_overduehas no filter reading it: its one consumer reads the value off a rowget_recordalready fetched. The field's comment says so and forbids adding such a filter.Acceptance (the ruling's two legs)
Leg 1 — the number reaches the consumer. The ruling offers two pin sites: the flow's
notifystep output, or the record projection theloopiterates. This PR pins the second, and the reason is in the acceptance notes below.examples/app-todo/test/overdue-escalation-days-overdue.test.tsasserts that every{currentTask.DOT_TOKEN}in the app's real notify body names a key the projected row carries and renders non-blank, and that the value is the real span (5 days overdue reads 5).Leg 2 —
objectstack validatereports no template-path warning for this flow. Measured both ways, by ablating the field and re-running:objectstack validateonexamples/app-todoorigin/main)flow "overdue_escalation" node "notify": template references '{currentTask.days_overdue}', but 'days_overdue' is not a field on object 'todo_task' — it resolves to an empty string at runtime (silently).Validation passed· exit 0Reverse verification
One-off, run from the committed fix and restored; no permanent artifact.
node scripts/ablation-replace.mjs --file examples/app-todo/src/objects/task.object.ts --anchor ... --deletereportedanchor 1 -> 0, blob bae175811d2b -> 3bccf64d25ce.notify body names {currentTask.days_overdue}: expected ... to have property "days_overdue"— the card's defect, verbatim. The third test (the projection precondition) stays green, correctly: it is aboutfields, not about the field.blob == HEAD (bae175811d2b)andgit diff HEADempty.examples/app-todobuilds nodist(itsmainisobjectstack.config.ts) and the suite imports../src/objects/task.object.jsdirectly, so the mutation's only path to the run is the source file the tool hashed.Tests and gates
Measured on
255c04af6(the branch head this PR opens with).pnpm --filter @objectstack/example-todo test:: exit 0 — 233 passed (233), 6 files. Three of those were red at first and are fixed here:translation-completeness.test.tsrequires a label in all three locales for every declared field, so the new field carriesDays Overdue/逾期天数/超過日数.pnpm --filter @objectstack/example-todo typecheck:: exit 0.pnpm --filter '@objectstack/example-todo^...' build:: exit 0 (dependency closure).node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack→ 37 families. All 37 run, exit code captured before any pipe; reconciled with--ran:37 derived, 36 run, 1 NOT-MEASURED, 0 UNRUN.pnpm check:dual-build-cjs-loads:: exit 3 —PREREQUISITE NOT MET — this gate reads built output, and some package has no dist/. Not a pass and not a failure; it needs a full workspace build this container did not run.npx eslint . --no-inline-config --format json:: exit 0 — not narrowed: the whole universe eslint's own config selects was linted, 6906 files, 0 errors, 0 warnings. Type-aware linting is not enabled ineslint.config.mjs(noparserOptions.project), so nothing in this diff could move a verdict on a file it does not touch.Changeset: measured
skip-changesetexamples/app-todo/package.jsondeclares"private": trueand nofilesarray, and no published package'sfiles[]ships anything fromexamples/. The diff therefore publishes nothing from any released package. Requesting theskip-changesetlabel — this seat's dispatch budget carries no label write.Acceptance notes
A defect measured on the way through, NOT fixed here, and it is the reason leg 1 pins the projection rather than the
notifystep output.overdue_escalation'sloopnode declares noconfig.body. That is the legacy flat-graph form (packages/services/service-automation/src/builtin/loop-node.ts:71): the node sets$loopItems/$loopIndexand returns without ever bindingiteratorVariable.update_priorityandnotify_ownersit on ordinary out-edges, which that node's own docblock calls "the after-loop continuation" — so they run once, after the loop, withcurrentTaskunbound.Observed by running the app's real flow through the real engine:
⇒ the run dies one node before
notify_owner, so today no escalation notice is sent at all — the card's described symptom (a notice with a blank where the count belongs) is not what the runtime does. Note this is not specific todays_overdue:{currentTask.subject},{currentTask.due_date},{currentTask.owner}and{currentTask.id}are all unbound by the same mechanism, and it predates and outlives this card.task_reminder, two declarations above in the same file, has the identical shape.Left for the triage seat as a separate class-(a) card rather than folded in: different mechanism (flow-graph structure, not a missing field), different repair (move the two nodes into a
config.bodyregion, which perflow-loop-body-uncontainedalso needs a per-iterationtry_catch— the worked form isexamples/app-showcase/src/automation/flows/index.ts:908), and it touches both flows in the file. Dedupe words:loop body,iteratorVariable,legacy flat-graph loop,overdue_escalation,currentTask unbound.Also noted, not filed:
pnpm --filter PKG build --concurrency=2forwards--concurrency=2into the receiving package script, andpackages/cli's build script ends infi, so the appended token makesshfail withSyntax error: word unexpectedand the closure build exits 2. Observed once here;--workspace-concurrency=2before--filteris the working spelling. Carrier: the next agent that copies the--concurrencyform from a dispatch order. This is a tooling-usage trap rather than a repo defect, so it is noted, not filed.Files changed (5)
examples/app-todo/src/objects/task.object.ts— the fieldexamples/app-todo/src/translations/{en,zh-CN,ja-JP}.ts— its label in all three localesexamples/app-todo/test/overdue-escalation-days-overdue.test.ts— new, the acceptance pin⛔ Draft on purpose: not flipped to ready and not enqueued.
Generated by Claude Code